﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using System.IO;

using CE.Mail;
using CE.Image;
using CE.Global;
using CE.User;
using CXDecryption;
using CE.Database;

public partial class car_insurance_payment_payment_message : MyLanguageBasePage
{
    public static Int64 _CarId, _CarMoreId, _UserId, _CXCTypeId, _ProviderId;
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        //UICulture = selectedCulture;
        Culture = selectedCulture;
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HyperLink _lnkTryAgain = new HyperLink();
            ibtnTryAgain.Attributes.Add("onmouseover", "this.src='" + _lnkTryAgain.ResolveClientUrl(Resources.ImageResource.TryAgainGreenUrl) + "';");
            ibtnTryAgain.Attributes.Add("onmouseout", "this.src='" + _lnkTryAgain.ResolveClientUrl(Resources.ImageResource.TryAgainBlueUrl) + "';");
            if (Request.Params["Ref"] != null && Request.Params["code"] != null) //Request.Params["successcode"] != null)
            {
                string _PaymentReturnMessage = "";
                txtOrderRefNo.Text = Request.Params["Ref"].ToString();
                if (Request.Params["successcode"] != null && Request.Params["PayRef"] != null && Request.Params["AuthId"] != null && Request.Params["eci"] != null)
                {
                    txtSuccesscode.Text = Request.Params["successcode"].ToString();
                    txtPayRef.Text = Request.Params["PayRef"].ToString();
                    txtAuthId.Text = Request.Params["AuthId"].ToString();
                    txtEci.Text = Request.Params["eci"].ToString();
                }
                else
                {
                    txtSuccesscode.Text = "";
                    txtPayRef.Text = "";
                    txtAuthId.Text = "";
                    txtEci.Text = "";
                }
                if (Request.Params["src"] != null)
                {
                    _PaymentReturnMessage += "src=" + Request.Params["src"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "src=N/A,";
                }
                if (Request.Params["prc"] != null)
                {
                    _PaymentReturnMessage += "prc=" + Request.Params["prc"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "prc=N/A,";
                }
                if (Request.Params["Ord"] != null)
                {
                    _PaymentReturnMessage += "Ord=" + Request.Params["Ord"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "Ord=N/A,";
                }
                if (Request.Params["Holder"] != null)
                {
                    _PaymentReturnMessage += "Holder=" + Request.Params["Holder"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "Holder=N/A,";
                }
                if (Request.Params["Amt"] != null)
                {
                    _PaymentReturnMessage += "Amt=" + Request.Params["Amt"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "Amt=N/A,";
                }
                if (Request.Params["Cur"] != null)
                {
                    _PaymentReturnMessage += "Cur=" + Request.Params["Cur"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "Cur=N/A,";
                }
                if (Request.Params["remark"] != null)
                {
                    _PaymentReturnMessage += "remark=" + Request.Params["remark"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "remark=N/A,";
                }
                if (Request.Params["payerAuth"] != null)
                {
                    _PaymentReturnMessage += "payerAuth=" + Request.Params["payerAuth"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "payerAuth=N/A,";
                }
                if (Request.Params["sourceIp"] != null)
                {
                    _PaymentReturnMessage += "sourceIp=" + Request.Params["sourceIp"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "sourceIp=N/A,";
                }
                if (Request.Params["ipCountry"] != null)
                {
                    _PaymentReturnMessage += "ipCountry=" + Request.Params["ipCountry"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "ipCountry=N/A,";
                }
                if (Request.Params["cc1316"] != null)
                {
                    _PaymentReturnMessage += "cc1316=" + Request.Params["cc1316"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "cc1316=N/A,";
                }
                if (Request.Params["cc0104"] != null)
                {
                    _PaymentReturnMessage += "cc0104=" + Request.Params["cc0104"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "cc0104=N/A,";
                }
                if (Request.Params["baseAmt"] != null)
                {
                    _PaymentReturnMessage += "baseAmt=" + Request.Params["baseAmt"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "baseAmt=N/A,";
                }
                if (Request.Params["baseCur"] != null)
                {
                    _PaymentReturnMessage += "baseCur=" + Request.Params["baseCur"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "baseCur=N/A,";
                }
                if (Request.Params["exRate"] != null)
                {
                    _PaymentReturnMessage += "exRate=" + Request.Params["exRate"].ToString() + ",";
                }
                else
                {
                    _PaymentReturnMessage += "exRate=N/A,";
                }

                Int64 _Result = 0;
                Int64 RefCEUserId = 0;
                Int64 CarId = 0;
                string strSql = "";
                MyDatabase _db = new MyDatabase();
                string _OrderRefNo = txtOrderRefNo.Text;
                string _successcode = txtSuccesscode.Text;
                string _PayRef = txtPayRef.Text;
                string _AuthId = txtAuthId.Text;
                string _eci = txtEci.Text;
                bool _PaymentStatus = false;
                Int16 _NonGGPaymentStatus = 0;
                Int16 _PaymentCode = Convert.ToInt16(Request.Params["code"].ToString());
                //if (Request.Params["successcode"].ToString() == "0")
                if (Request.Params["code"].ToString() == "1")
                {
                    _PaymentStatus = true;
                    _NonGGPaymentStatus = 1;
                }
                if (CheckApplicationType(txtOrderRefNo.Text.Trim()) == 1) //Online Application
                {
                    _Result = UpdateReturnMsg(_OrderRefNo, _successcode, _PayRef, _AuthId, _eci, _PaymentReturnMessage, _PaymentStatus, _PaymentCode);
                    if (_Result > 0)
                    {
                    }
                    else
                    {
                    }
                    //Sakthi on 27 Jun 2011 -- Start
                    strSql = "SELECT RefCEUserId,CarId FROM tblCarInsuranceSelectItemTH WHERE OrderRefNo = '" + txtOrderRefNo.Text.Trim() + "'";
                    DataTable _SelectItemResult = _db.GetDataTable(strSql);
                    if (_SelectItemResult != null && _SelectItemResult.Rows.Count > 0)
                    {
                        //object _objResult = _db.ExecuteScalarSqlStatement(strSql);
                        //if (_objResult != null)
                        //{
                        //RefCEUserId = Convert.ToInt64(_objResult.ToString());
                        RefCEUserId = Convert.ToInt64(_SelectItemResult.Rows[0]["RefCEUserId"].ToString());
                        CarId = Convert.ToInt64(_SelectItemResult.Rows[0]["CarId"].ToString());
                        Account _account = new Account();
                        AccountDB _accountdb = new AccountDB();
                        _account = _accountdb.GetUserAccount(RefCEUserId, Convert.ToInt32(CE.Global.CEUserType.Customer));
                        if (_account != null)
                        {
                            GetUserInformation(_account);
                        }
                    }
                    //Sakthi on 27 Jun 2011 -- End
                }
                else if (CheckApplicationType(txtOrderRefNo.Text.Trim()) == 2) //NonGG Application
                {
                    _Result = UpdateNonGGReturnMsg(_OrderRefNo, _successcode, _PayRef, _AuthId, _eci, _PaymentReturnMessage, _NonGGPaymentStatus, _PaymentCode);

                    strSql = "SELECT RefCEUserId,CECarId FROM tblNonGGCarMoreDetails WHERE OrderRefNo = '" + txtOrderRefNo.Text.Trim() + "'";
                    DataTable _SelectItemResult = _db.GetDataTable(strSql);
                    if (_SelectItemResult != null && _SelectItemResult.Rows.Count > 0)
                    {                       
                        RefCEUserId = Convert.ToInt64(_SelectItemResult.Rows[0]["RefCEUserId"].ToString());
                        CarId = Convert.ToInt64(_SelectItemResult.Rows[0]["CECarId"].ToString());
                        Account _account = new Account();
                        AccountDB _accountdb = new AccountDB();
                        _account = _accountdb.GetUserAccount(RefCEUserId, Convert.ToInt32(CE.Global.CEUserType.Customer));
                        if (_account != null)
                        {
                            GetUserInformation(_account);
                        }
                    }
                }

                //Sakthi on 22 Feb 2012 -- Start
                strSql = "";
                string _redirectUrl = "~/car-insurance/payment/user-message.aspx";

                Int16 _LanguageId = 0;
                strSql = "SELECT IsEnglish FROM tblCarDetailTH WHERE CarId  = " + CarId.ToString();
                object _IsEnglish = _db.ExecuteScalarSqlStatement(strSql);
                if (_IsEnglish != null)
                {
                    _LanguageId = Convert.ToInt16(_IsEnglish.ToString());
                }
                if (_LanguageId == 0)
                {
                    _redirectUrl = "~/car-insurance/payment/user-message.aspx";
                }
                else if (_LanguageId == 1)
                {
                    _redirectUrl = "~/en/car-insurance/payment/user-message.aspx";
                }
                Session[CE.Global.General.OrderRefNo] = txtOrderRefNo.Text;
                Session[CE.Global.General.PayMailStatus] = "1";
                Response.Redirect(_redirectUrl);
                //Sakthi on 22 Feb 2012 -- End


                ////if (Request.Params["successcode"].ToString() == "0")
                //if (Request.Params["code"].ToString() == "1")
                //{
                //    divMsgType1.Visible = false;
                //    divMsgType2.Visible = true;
                //    ProposalNotification();
                //}
                //else
                //{
                //    divMsgType1.Visible = true;
                //    divMsgType2.Visible = false;
                //}

            }
            else
            {
                txtOrderRefNo.Text = "";
            }
        }
    }

    public Int64 UpdateReturnMsg(string OrderRefNo, string successcode, string PayRef, string AuthId, string eci, string ReturnMsg, bool PaymentStatus, Int16 PaymentCode)
    {
        Int64 _result = -1;
        string _spName = "[sprocUpdatePaymentConfirmationStatus]";
        MyDatabase _db = new MyDatabase();
        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@OrderRefNo", OrderRefNo);
        _sPara.Add("@successcode", successcode);
        _sPara.Add("@PayRef", PayRef);
        _sPara.Add("@AuthId", AuthId);
        _sPara.Add("@eci", eci);
        _sPara.Add("@ReturnMsg", ReturnMsg);
        _sPara.Add("@PaymentStatus", PaymentStatus);
        _sPara.Add("@PaymentCode", PaymentCode);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    public Int64 UpdateNonGGReturnMsg(string OrderRefNo, string successcode, string PayRef, string AuthId, string eci, string ReturnMsg, Int16 PaymentStatus, Int16 PaymentCode)
    {
        Int64 _result = -1;
        string _spName = "[sprocUpdateNonGGPaymentConfirmationStatus]";
        MyDatabase _db = new MyDatabase();
        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@OrderRefNo", OrderRefNo);
        _sPara.Add("@successcode", successcode);
        _sPara.Add("@PayRef", PayRef);
        _sPara.Add("@AuthId", AuthId);
        _sPara.Add("@eci", eci);
        _sPara.Add("@ReturnMsg", ReturnMsg);
        _sPara.Add("@PaymentStatus", PaymentStatus);
        _sPara.Add("@PaymentCode", PaymentCode);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    protected void ibtnTryAgain_Click(object sender, EventArgs e)
    {
        if (txtOrderRefNo.Text != "")
        {
            MyDatabase _db = new MyDatabase();
            float _fAmount = 0.0f;
            string strSql = "SELECT CAST(AnnualPremium AS NUMERIC(10,2)) AS AnnualPremium FROM tblCarInsuranceSelectItemTH WHERE OrderRefNo  = '" + txtOrderRefNo.Text + "'";
            object _result = _db.ExecuteScalarSqlStatement(strSql);
            if (_result != null)
            {
                _fAmount = Convert.ToSingle(_result.ToString());
            }

            string _strAmount, eAmount, _strOrderRefNo, eOrderRefNo;
            _strAmount = ""; eAmount = ""; _strOrderRefNo = ""; eOrderRefNo = "";
            string key = "cxDAtravel";
            CXDecryption.Decryption cxd = new CXDecryption.Decryption();
            _strAmount = _fAmount.ToString();
            _strOrderRefNo = txtOrderRefNo.Text;
            if (_strAmount.ToString() != "" && _strAmount.ToString() != null)
            {
                byte[] Amount = cxd.Encrypt(_strAmount, key);
                eAmount = Convert.ToBase64String(Amount);
            }
            if (_strOrderRefNo.ToString() != "" && _strOrderRefNo.ToString() != null)
            {
                byte[] OrderRefNo = cxd.Encrypt(_strOrderRefNo, key);
                eOrderRefNo = Convert.ToBase64String(OrderRefNo);
            }
            string URL = ConfigurationManager.AppSettings["TH.BKKPaymentPage"].ToString();
            URL += "pa=" + eAmount + "&orno=" + eOrderRefNo;
            //string URL = "http://203.142.18.110/bkk_test/MethodOne.aspx?pa=" + eAmount + "&orno=" + eOrderRefNo;
            Response.Redirect(URL);
        }
    }

    private void ProposalNotification()
    {
        string _strSql, _providerName, _ToEmail, _CCEmail, _BCCEmail, _Date, _Time, _InsuranceName, _RefNo;
        MyDatabase _db = new MyDatabase();
        DataTable _dtProvider = new DataTable();
        DataTable _dtInsurance = new DataTable();
        _Date = "";
        _Time = "";
        _RefNo = "";
        _strSql = "";
        _providerName = "";
        _ToEmail = "";
        _CCEmail = "";
        _BCCEmail = "";
        _InsuranceName = "Car Insurance";

        if (Request.Params["Ref"] != null)
        {
            _strSql = "SELECT ProviderCompanyId,CarId,RefCEUserId FROM tblCarInsuranceSelectItemTH WHERE OrderRefNo = '" + Request.Params["Ref"].ToString() + "'";
            DataTable _dtResult = _db.GetDataTable(_strSql);
            if (_dtResult.Rows.Count > 0)
            {
                _ProviderId = Convert.ToInt64(_dtResult.Rows[0]["ProviderCompanyId"].ToString());
                _CarId = Convert.ToInt64(_dtResult.Rows[0]["CarId"].ToString());
                _UserId = Convert.ToInt64(_dtResult.Rows[0]["RefCEUserId"].ToString());
                if (Session[General.UserEmail] != null)
                {
                    _ToEmail = Session[General.UserEmail].ToString();
                }
                else
                {
                    SortedList _sPara = new SortedList();
                    _sPara.Add("@CEID", _UserId);
                    string _spName = "sprocUserSelectSingleItem";
                    DataTable _dtUserEmail = _db.GetDataTableBySP(_spName, _sPara);
                    if (_dtUserEmail.Rows.Count > 0)
                    {
                        _ToEmail = _dtUserEmail.Rows[0]["Email"].ToString();
                    }
                }
                _strSql = "";
                _strSql = "SELECT [CompanyName], [Email1], [PhoneNo1] FROM tblProviderCompany WHERE ProviderCompanyId = " + _ProviderId.ToString();

                _dtProvider = _db.GetDataTable(_strSql);
                if (_dtProvider.Rows.Count > 0)
                {
                    _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
                    _CCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_CC");
                    _BCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_BCC");
                }
                string Table = GetCarMoreDetailsTableName(_ProviderId);
                _strSql = "";
                _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time],[QuoteRefNo] ";
                _strSql += " FROM  " + Table + " WHERE CECarId = " + _CarId.ToString() + " ORDER BY ModifiedDate DESC";
                _dtInsurance = _db.GetDataTable(_strSql);
                if (_dtInsurance.Rows.Count > 0)
                {
                    _Date = _dtInsurance.Rows[0]["Date"].ToString();
                    _Time = _dtInsurance.Rows[0]["Time"].ToString();
                    _RefNo = _dtInsurance.Rows[0]["QuoteRefNo"].ToString();
                }
                //bool _PaymentComplete = true;
                //if (Request.Params["successcode"] != null && Request.Params["successcode"].ToString() != "0")
                //{
                //    _PaymentComplete = false;
                //}
                if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
                {
                    MailManagerTH.SendCarProposalNotificationToUser(_providerName, _ToEmail, _CCEmail, _BCCEmail, _InsuranceName, _Date, _Time, _RefNo, "CC");
                }
            }
        }
    }

    public string GetCarMoreDetailsTableName(Int64 ProviderId)
    {
        string _TableName = "";
        if (ProviderId == 11)
        {
            _TableName = "tblCarMoreDetail_AZCp";
        }
        else if (ProviderId == 12)
        {
            _TableName = "tblCarMoreDetail_MSIG";
        }
        else if (ProviderId == 16)
        {
            _TableName = "tblCarMoreDetail_AXA";
        }
        else if (ProviderId == 29)
        {
            _TableName = "tblCarMoreDetail_LMG";
        }
        else if (ProviderId == 31)
        {
            _TableName = "tblCarMoreDetail_Chartis";
        }
        else if (ProviderId == 32)
        {
            _TableName = "tblCarMoreDetail_BKI";
        }
        else if (ProviderId == 33)
        {
            _TableName = "tblCarMoreDetail_MTI";
        }
        else if (ProviderId == 35)
        {
            _TableName = "tblCarMoreDetail_KPI";
        }
        else if (ProviderId == 39)
        {
            _TableName = "tblCarMoreDetail_Mittare";
        }
        else if (ProviderId == 41)
        {
            _TableName = "tblCarMoreDetail_Kurnia";
        }
        else if (ProviderId == 43)
        {
            _TableName = "tblCarMoreDetail_SMK";
        }
        else if (ProviderId == 45)
        {
            _TableName = "tblCarMoreDetail_Viriyah";
        }
        else if (ProviderId == 46)
        {
            _TableName = "tblCarMoreDetail_TMS";
        }
        else if (ProviderId == 58)
        {
            _TableName = "tblCarMoreDetail_TVV";
        }
        return _TableName;
    }

    private void GetUserInformation(Account _account)
    {
        DateTime dtNow = new DateTime();
        dtNow = DateTime.Now;
        Session[CE.Global.General.UserId] = _account.CEID;
        Session[CE.Global.General.UserTypeId] = _account.UserTypeId;

        if (_account.UserTypeId == Convert.ToInt32(CE.Global.CEUserType.Provider))
        {
            CE.Provider.ProviderCompanyLink _comlink = new CE.Provider.ProviderCompanyLink();
            CE.Provider.ProviderCompanyLinkDB _comlinkdb = new CE.Provider.ProviderCompanyLinkDB();
            _comlink = _comlinkdb.GetProviderCompanyId(_account.CEID);
            if (_comlink != null)
            {
                Session[CE.Global.General.ProviderCompanyId] = _comlink.ProviderCompanyId;
            }
        }

        Session[CE.Global.General.UserEmail] = _account.Email;
        Session[CE.Global.General.StartTime] = dtNow.ToString();
        bool isProfileComplete = false;
        bool isContactComplete = false;

        ProfileDB _profiledb = new ProfileDB();
        Profile _profile = new Profile();
        Contact _contact = new Contact();
        ContactDB _contactdb = new ContactDB();

        _contact = _contactdb.GetContact(_account.CEID);

        _profile = _profiledb.GetProfile(_account.CEID);

        if (_contact != null)
        {
            isContactComplete = true;
            Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
        }
        else
        {
            Session[CE.Global.General.UserPhoneNo] = null;
        }

        if (_profile != null)
        {
            if (_profile.FirstName != null && _profile.FirstName != string.Empty)
            {
                Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.FirstName) + " " + Server.HtmlDecode(_profile.SurName);
            }
            else
            {
                Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.SurName);
            }

            if (!string.IsNullOrEmpty(_profile.IDType) &&
                !string.IsNullOrEmpty(_profile.IDNo) &&
                _profile.IDNo.Length == 9)
            {
                Session[CE.Global.General.UserICNumber] = _profile.IDType + " " + _profile.IDNo;
            }

            if (_profile.Status.ToLower() == "complete")
            {
                isProfileComplete = true;
            }
            else
            {
                isProfileComplete = false;
            }
        }
        else
        {
            Session[CE.Global.General.UserName] = null;
        }

        if (isProfileComplete && isContactComplete)
        {
            Session[CE.Global.General.UserProfileAndContactComplete] = "1";
        }
        else
        {
            Session[CE.Global.General.UserProfileAndContactComplete] = "0";
        }

    }

    private Int16 CheckApplicationType(string OrderRefNo)
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT OrderRefNo FROM [tblCMIDetail] WHERE OrderRefNo = " + OrderRefNo + " ORDER BY CMIId DESC  ";
        object _resultcmi = _db.ExecuteScalarSqlStatement(strSql);
        if (_resultcmi != null && Convert.ToInt64(_resultcmi.ToString()) > 0)
        {
            string _redirectCMI = "~/cmi/complete-cmi.aspx";
            if (Request.Params["src"] != null)
            {
                _redirectCMI += "src=" + Request.Params["src"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "src=N/A,";
            }
            if (Request.Params["prc"] != null)
            {
                _redirectCMI += "prc=" + Request.Params["prc"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "prc=N/A,";
            }
            if (Request.Params["Ord"] != null)
            {
                _redirectCMI += "Ord=" + Request.Params["Ord"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "Ord=N/A,";
            }
            if (Request.Params["Holder"] != null)
            {
                _redirectCMI += "Holder=" + Request.Params["Holder"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "Holder=N/A,";
            }
            if (Request.Params["Amt"] != null)
            {
                _redirectCMI += "Amt=" + Request.Params["Amt"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "Amt=N/A,";
            }
            if (Request.Params["Cur"] != null)
            {
                _redirectCMI += "Cur=" + Request.Params["Cur"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "Cur=N/A,";
            }
            if (Request.Params["remark"] != null)
            {
                _redirectCMI += "remark=" + Request.Params["remark"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "remark=N/A,";
            }
            if (Request.Params["payerAuth"] != null)
            {
                _redirectCMI += "payerAuth=" + Request.Params["payerAuth"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "payerAuth=N/A,";
            }
            if (Request.Params["sourceIp"] != null)
            {
                _redirectCMI += "sourceIp=" + Request.Params["sourceIp"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "sourceIp=N/A,";
            }
            if (Request.Params["ipCountry"] != null)
            {
                _redirectCMI += "ipCountry=" + Request.Params["ipCountry"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "ipCountry=N/A,";
            }
            if (Request.Params["cc1316"] != null)
            {
                _redirectCMI += "cc1316=" + Request.Params["cc1316"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "cc1316=N/A,";
            }
            if (Request.Params["cc0104"] != null)
            {
                _redirectCMI += "cc0104=" + Request.Params["cc0104"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "cc0104=N/A,";
            }
            if (Request.Params["baseAmt"] != null)
            {
                _redirectCMI += "baseAmt=" + Request.Params["baseAmt"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "baseAmt=N/A,";
            }
            if (Request.Params["baseCur"] != null)
            {
                _redirectCMI += "baseCur=" + Request.Params["baseCur"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "baseCur=N/A,";
            }
            if (Request.Params["exRate"] != null)
            {
                _redirectCMI += "exRate=" + Request.Params["exRate"].ToString() + ",";
            }
            else
            {
                _redirectCMI += "exRate=N/A,";
            }
            Response.Redirect(_redirectCMI);
        }

        Int16 _result = 0;
        if (OrderRefNo.Length > 11)
        {
            string val = "0";
            val = OrderRefNo.Substring(10, 1);
            _result = Convert.ToInt16(val);
        }
        return _result;
    }

}
